import { marked } from '/node_modules/marked/lib/marked.esm.js';

export const markdownLoader = {
    async loadMarkdown(path) {
        try {
            const response = await fetch(path);
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            const markdown = await response.text();
            marked.setOptions({
                gfm: true,
                breaks: true,
                highlight: function(code, lang) {
                    return code;
                }
            });
            return marked.parse(markdown);
        } catch (error) {
            console.error('Error loading markdown:', error);
            return '<p class="text-red-500">加载笔记内容失败</p>';
        }
    }
}; 